//-----------------------------------------------------------------------------
// Copyright (c) 2011 David Waby
// Initially created on 02/11/2011
//-----------------------------------------------------------------------------

#include "Global.h"
#include "TileAttributePortal.h"
#include "EventManager.h"
#include "EventLoadMap.h"
#include "Tile.h"

//-----------------------------------------------------------------------------
TileAttributePortal::TileAttributePortal()
:	m_targetMapID(0)
{
} 

//-----------------------------------------------------------------------------
TileAttributePortal::~TileAttributePortal()
{
}

//-----------------------------------------------------------------------------
void TileAttributePortal::OnEnter()
{
}

//-----------------------------------------------------------------------------
void TileAttributePortal::Use()
{
	EventManager::Get().PostEvent(EventLoadMap(m_targetMapID, &m_targetTilePosition));
}

//-----------------------------------------------------------------------------
void TileAttributePortal::OnExit()
{
}

//-----------------------------------------------------------------------------
unsigned int TileAttributePortal::GetAttributeType() const
{ 
	return Tile::TileAttributes::Portal; 
}

//-----------------------------------------------------------------------------
void TileAttributePortal::Serialise(Json::Value * o_root) const
{
}

//-----------------------------------------------------------------------------
void TileAttributePortal::Deserialise(Json::Value const * i_root)
{
	// Read in the target map id
	m_targetMapID = (*i_root)["id"].asInt();

	// Get the target tile position
	m_targetTilePosition.Deserialise(&((*i_root)["dest"]));
}